package com.cande.loki.exercise.design;

/**
 * @BelongsProject: loki
 * @BelongsPackage: com.cande.loki.exercise.design
 * @Author: WANGAOFEI
 * @CreateTime: 2023-08-07  15:14
 * @Description: 单例模式
 * @Version: 1.0
 */
public class Singleton {
    private volatile static Singleton singleton;
//    private Singleton(){}


    public static Singleton getInstance(){
        if(singleton == null){
            synchronized(Singleton.class){
                if(singleton == null) {
                    singleton = new Singleton();   //创建实例
                }
            }
        }
        return singleton;
    }


    public static volatile Singleton singleton1;
    public Singleton() {};
    public Singleton getInstance1(){
        if (singleton1 == null){
            synchronized (Singleton.class){
                if (singleton1 ==null){
                    singleton1 = new Singleton();

                }
            }
        }
        return singleton1;
    }
}
